import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { CaptchaResult, LoginData, ExamLoginData, LoginResult } from "./types";

/**
 * 管理登录API
 *
 * @param data {LoginData}
 * @returns
 */
export function loginApi(data: LoginData): AxiosPromise<LoginResult> {
  const formData = new FormData();
  formData.append("username", data.username);
  formData.append("password", data.password);
  // formData.append("captchaKey", data.captchaKey || "");
  // formData.append("captchaCode", data.captchaCode || "");
  return request({
    // url: "/auth/doLogin",
    url: "/adminApi/auth/doLogin",
    method: "post",
    data: formData,
  });
}

/**
 * 考试登录API
 *
 * @param data {LoginData}
 * @returns
 */
export function examLoginApi(data: ExamLoginData): AxiosPromise<LoginResult> {
  return request({
    url: "/examApi/auth/doLogin",
    method: "post",
    data: data,
  });
}

/**
 * 注销API
 */
export function logoutApi() {
  return request({
    url: "/adminApi/logout",
    method: "delete",
  });
}

/**
 * 获取验证码
 */
export function getCaptchaApi(): AxiosPromise<CaptchaResult> {
  return request({
    url: "/adminApi/captcha",
    method: "get",
  });
}
